import type { AjaxPagingParams } from '@/types'

// #region 选择器选项处理
/** 每页显示个数选择器的选项设置 */
export const PAGE_SIZES: number[] = []

// window.addEventListener('resize', handleResize);
function handleResize() {
  const arr: number[] = []
  if (window.innerWidth >= 1920) {
    arr.push(...[20, 30, 50, 100])
  }
  else if (window.innerWidth >= 1440) {
    arr.push(...[15, 30, 50, 100])
  }
  else {
    arr.push(...[12, 30, 50, 100])
  }
  PAGE_SIZES.length = 0
  PAGE_SIZES.push(...arr)
}
handleResize()

// #endregion

/** 分页默认值 */
export const PARAMS: AjaxPagingParams = {
  pageNumber: 1,
  pageSize: PAGE_SIZES[0]!,
}

/**
 * 区间快捷-月
 */
export const RANGE_SHORTCUTS_MONTH = [
  {
    text: '当年',
    value: () => {
      const end = new Date()
      const start = new Date(new Date().getFullYear(), 0)
      return [start, end]
    },
  },
  {
    text: '最近一年',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setMonth(start.getMonth() - 11)
      return [start, end]
    },
  },
]
/**
 * 区间快捷-日
 */
export const RANGE_SHORTCUTS_DAY = [
  {
    text: '往后一星期',
    value: () => {
      const start = new Date()
      const end = new Date()
      end.setDate(start.getDate() + 7)
      return [start, end]
    },
  },
  {
    text: '往后一月',
    value: () => {
      const start = new Date()
      const end = new Date()
      end.setMonth(start.getMonth() + 1)
      return [start, end]
    },
  },
  {
    text: '当前星期',
    value: () => {
      const start = new Date()
      const end = new Date()
      end.setDate(start.getDate() + 7 - start.getDay())
      return [start, end]
    },
  },
  {
    text: '当月',
    value: () => {
      const current = new Date()
      const month = current.getMonth()

      const start = new Date(
        current.getFullYear(),
        month,
        1,
      )
      const end = new Date(
        current.getFullYear(),
        month + 1,
        0,
      )
      return [start, end]
    },
  },
  {
    text: '最近一星期',
    value: () => {
      const end = new Date()
      const start = new Date()
      start.setDate(end.getDate() - 7)
      return [start, end]
    },
  },
  {
    text: '最近一月',
    value: () => {
      const start = new Date()
      const end = new Date()
      start.setDate(end.getDate() - 30)
      // console.log(formatTime(start), formatTime(end));
      return [start, end]
    },
  },
]

/** 禁用以后的日期 */
export function handleDisabledDate(date: Date) {
  const current = new Date()
  const t = date.getTime()
  return t > current.getTime()
  // return month !== targetMonth;
}
/** 禁用以后的小时 */
export function handleDisabledHours() {
  const current = new Date()
  const hours = current.getHours()
  return [...range(hours, 24)]
}
/** 禁用以后的分钟 */
export function handleDisabledMinutes() {
  const current = new Date()
  const minutes = current.getMinutes()
  return [...range(minutes, 60)]
}
